package com.example.smart_city_0829.activity.youth_lnn;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smart_city_0829.R;
import com.example.smart_city_0829.base.BaseActivity;
import com.example.smart_city_0829.entity.YouthInn.InnDetail;
import com.example.smart_city_0829.retrofit.NetCallBack;
import com.example.smart_city_0829.utils.Constant;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import retrofit2.Call;
import retrofit2.Response;

public class InnDetailActivity extends BaseActivity {

    private int innId = -1;

    private Banner banner;
    private TextView adress;
    private TextView phone;
    private TextView inTime;
    private TextView remaining;
    private TextView introduce;
    private TextView internalFacilities;
    private TextView surroundingFacilities;
    private TextView specialService;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_inn_detail;
    }

    @Override
    protected void initView() {
        banner = (Banner) findViewById(R.id.banner);
        adress = (TextView) findViewById(R.id.adress);
        phone = (TextView) findViewById(R.id.phone);
        inTime = (TextView) findViewById(R.id.in_time);
        remaining = (TextView) findViewById(R.id.remaining);
        introduce = (TextView) findViewById(R.id.introduce);
        internalFacilities = (TextView) findViewById(R.id.internalFacilities);
        surroundingFacilities = (TextView) findViewById(R.id.surroundingFacilities);
        specialService = (TextView) findViewById(R.id.specialService);
    }

    @Override
    protected void initData() {
        innId = getIntent().getIntExtra("id", -1);
        banner.setImageLoader(new ImageLoader() {
            @Override
            public void displayImage(Context context, Object o, ImageView imageView) {
                Glide.with(context)
                        .load(Constant.BASE_URL + o)
                        .into(imageView);
            }
        });
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected String getActionBarTitle() {
        return "驿站详情";
    }

    @Override
    protected void onResume() {
        super.onResume();
        getInnDetail();
    }

    private void getInnDetail(){
        api.getInnDetail(innId).enqueue(new NetCallBack<InnDetail>() {
            @Override
            public void onResponse(Call<InnDetail> call, Response<InnDetail> response) {
                final InnDetail.DataBean data = response.body().getData();

                banner.setImages(data.getImageUrlList());

                adress.setText(data.getAddress());
                phone.setText(data.getPhone()+"");
                inTime.setText(data.getWorkTime());
                remaining.setText("剩余男床位：" + data.getBedsCountBoy() + "\t" + "剩余女床位："+data.getBedsCountGirl());

                introduce.setText(data.getIntroduce());
                internalFacilities.setText(data.getInternalFacilities());
                surroundingFacilities.setText(data.getSurroundingFacilities());
                specialService.setText(data.getSpecialService());

                banner.start();
                banner.startAutoPlay();
            }
        });
    }
}